Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify NSModel to use boost variant. #693

Merged
merged 6 commits into from Jun 20, 2016

Conversation

MarcosPividori
Copy link
Contributor

No description provided.

@@ -13,12 +13,24 @@
#include <mlpack/core/tree/binary_space_tree.hpp>
#include <mlpack/core/tree/cover_tree.hpp>
#include <mlpack/core/tree/rectangle_tree.hpp>

#include <boost/variant.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add 'variant' to the list of Boost libraries we require in the documentation and in the root CMakeLists.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a header only library, so we don't need to include it in CMakeList.txt.
I can see that all boost dependencies mentioned in the README file: program_options, math_c99, unit_test_framework, and serialization, are not header only. Should I include variant there anyway? even if it is header only?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it is header only. I am not sure if it is possible to have a Boost installation where some of the header-only libraries (but not all) are available; I haven't played with b2 (Boost's build system) enough recently to be sure. If it's possible to have a Boost installation with some of the header-only libraries omitted, then we should include variant in there; otherwise, I don't think it's necessary. But I'm not sure whether or not that's possible...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a quick search, it looks like there is no such option to omit some header files...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks like there is nothing special we need to do with our CMake configuration for this change then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we don't have to add boost::variant to required libraries?? Even if its header only we need to make sure the headers are present. Or is it the part of basic boost which is included in every boost package?? I mean if I install just boost::math in ubuntu with apt-get do I get boost::variant??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see a note about this in boost's documentation: [ref]
"Other Packages
RedHat, Debian, and other distribution packagers supply Boost library packages, however you may need to adapt these instructions if you use third-party packages, because their creators usually choose to break Boost up into several packages, reorganize the directory structure of the Boost distribution, and/or rename the library binaries. If you have any trouble, we suggest using an official Boost distribution from SourceForge. "

I am not sure. But it looks like all partial packages depends on libboost-dev package, so they will finally include all headers files.
For example: libboost-program-options-dev --depends on--> libbooost-dev

@MarcosPividori
Copy link
Contributor Author

MarcosPividori commented Jun 13, 2016

The problem with appveyor is similar to this one: #476
With "using NSType = ...".

 error C3200: 'BinarySpaceTree<MetricType,mlpack::neighbor::NeighborSearchStat<Unique-Type-SortPolicy>,
 MatType,mlpack::bound::HRectBound,mlpack::tree::MidpointSplit>::DualTreeTraverser':
 invalid template argument for template parameter 'TraversalType', expected a class template

@rcurtin @stereomatchingkiss Any suggestion?
It is a bit difficult to debug from my linux computer.

arma::mat& distances);
};

class SearchVisitor : public boost::static_visitor<void>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should change the name of this class and SearchKVisitor to BichromaticSearchVisitor and MonochromaticSearchVisitor, respectively, for clarity? I couldn't think of any shorter names to differentiate there, but maybe you have a better idea? The root of my concern is that Search and SearchK don't really describe the difference in what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I agree. I will change this.

@MarcosPividori MarcosPividori force-pushed the variants-for-ns-model branch 2 times, most recently from 1b87667 to a0bcee9 Compare June 15, 2016 02:55
@stereomatchingkiss
Copy link
Contributor

Hi, Marcos, I found a way to mimic alias template, please check the codes at pastebin.

…rainVisitor.

Also, add a more specific definition of NSTypeT, to avoid vc compiler errors.
@MarcosPividori
Copy link
Contributor Author

@stereomatchingkiss thanks!! I am considering that option.

@MarcosPividori
Copy link
Contributor Author

@stereomatchingkiss AppVeyor succeeded! I have made it a little different to avoid code bloat.

@MarcosPividori
Copy link
Contributor Author

I think this is ready to be merged. Please let me know if you want me to improve something.

@@ -37,6 +49,127 @@ struct NSModelName<FurthestNeighborSort>
static const std::string Name() { return "furthest_neighbor_search_model"; }
};

class MonoSearchVisitor : public boost::static_visitor<void>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I hate to be picky, so I hope I am not giving too much work, but do you think you could add documentation for these classes and their members and member functions? I am not sure everyone who looks through this file will be familiar with the visitor paradigm; there is no need to explain what that is in your comments, but it may be useful to have comments along the lines of "MonoSearchVisitor executes a monochromatic neighbor search on the given NSType", or something like this. Maybe a few more words are useful to explain that better. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I should add, if you don't want to or are busy doing other things, I can do the documentation here, it will only take a few minutes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcurtin Sure!! I am here for this! I agree it can be confusing for someone with no knowledge of boost variants. I will add documentation.
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in: 6c2c3ca

@MarcosPividori
Copy link
Contributor Author

MarcosPividori commented Jun 17, 2016

Hi, in b34dac8 , I fixed serialization of NSModel. Loading was not working before that commit.
I use the serialize function for variants, defined by boost. So, I had to add a definition of serialize for NeighborSearchClass, because it is need by boost variant serialization.
Another option to fixing the serialization can be seeing in this branch: https://github.com/MarcosPividori/mlpack/tree/variant-serialization , but I prefer the solution included above, because it is simpler.

@rcurtin
Copy link
Member

rcurtin commented Jun 17, 2016

Everything looks good to me; @sumedhghaisas, I have no more comments, so feel free to merge when you are happy. :)

@sumedhghaisas sumedhghaisas merged commit 779556f into mlpack:master Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants